package com.tourism.website.articledisplay.controller;

import com.tourism.website.apis.ArticleDisplayApis;
import com.tourism.website.articledisplay.service.IArticleCategoryService;
import com.tourism.website.articledisplay.service.IArticleImgService;
import com.tourism.website.articledisplay.service.IArticleService;
import com.tourism.website.articledisplay.service.ICategoryService;
import com.tourismwebsite.articledisplay.dto.ArticleCategoryDTO;
import com.tourismwebsite.articledisplay.dto.ArticleDTO;
import com.tourismwebsite.articledisplay.dto.ArticleImgDTO;
import com.tourismwebsite.articledisplay.dto.CategoryDTO;
import com.tourismwebsite.vo.JsonVO;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiImplicitParam;
import io.swagger.annotations.ApiOperation;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import javax.annotation.Resource;
import javax.validation.constraints.NotNull;
import java.util.List;

@RestController
@RequestMapping("/articledisplay")
@Validated
@Api(tags = "文章展示管理")
public class ArticleDisplayController implements ArticleDisplayApis {
    @Resource
    IArticleCategoryService articleCategoryService;
    @Resource
    ICategoryService categoryService;
    @Resource
    IArticleService articleService;
    @Resource
    IArticleImgService articleImgService;

    /**
     * 查询文章内容信息
     * @param articleId
     * @return
     */
    @Override
    public JsonVO<ArticleDTO> queryArticleContent(Integer articleId) {
        ArticleDTO articleDTO=articleService.queryArticleContent(articleId);
        return  JsonVO.success(articleDTO);
    }
    @GetMapping("/query-article-content")
    @ApiOperation(value = "查询文章内容信息")
    @ApiImplicitParam(name="articleId",value = "文章ID",paramType="query")
    public JsonVO<ArticleDTO> queryArticleContentValidated(@NotNull(message = "文章ID不可为空") Integer articleId){
        return queryArticleContent(articleId);
    }

    /**
     * 查询文章ID
     * @param categoryId
     * @return
     */

    @Override
    public JsonVO<List<ArticleCategoryDTO>> queryArticleID(Integer categoryId) {
        List<ArticleCategoryDTO> articleCategoryDTOS=articleCategoryService.queryArticleID(categoryId);
        return JsonVO.success(articleCategoryDTOS);
    }
    @GetMapping("/query-article-category")
    @ApiOperation(value = "查询文章ID")
    @ApiImplicitParam(name="articleId",value = "文章ID",paramType="query")
    public JsonVO<List<ArticleCategoryDTO>> queryArticleIDValidated(@NotNull Integer categoryId){
        return queryArticleID(categoryId);
    }

    /**
     * 查询文章标题以及时间
     * @param articleId
     * @return
     */

    @Override
    public JsonVO<ArticleDTO> queryArticleNameAndTime(Integer articleId) {
        ArticleDTO articleDTO=articleService.queryArticleNameAndTime(articleId);
        return JsonVO.success(articleDTO);
    }
    @GetMapping("/query-article-name")
    @ApiOperation(value = "查询文章标题以及时间")
    @ApiImplicitParam(name="articleId",value = "文章ID",paramType="query")
    public JsonVO<ArticleDTO> queryArticleNameAndTimeValidated(@NotNull Integer articleId) {
        return queryArticleNameAndTime(articleId);
    }

    /**
     * 查询全部类别名
     * @return
     */
    @GetMapping("/query-all-category")
    @ApiOperation(value = "查询全部类别名")
    @Override
    public JsonVO<List<CategoryDTO>> queryAllCategory() {
        List<CategoryDTO> categoryDTOS=categoryService.queryAllCategory();
        return JsonVO.success(categoryDTOS);
    }

    /**
     * 查询文章包含图片
     * @param articleId
     * @return
     */

    @Override
    public JsonVO<List<ArticleImgDTO>> queryArticleImg(Integer articleId) {
        List<ArticleImgDTO> articleImgDTOS=articleImgService.queryArticleImg(articleId);
        return JsonVO.success(articleImgDTOS);
    }
    @GetMapping("/query-article-img")
    @ApiOperation(value = "查询文章包含图片")
    @ApiImplicitParam(name="articleId",value = "文章ID",paramType="query")
    public JsonVO<List<ArticleImgDTO>> queryArticleImgValidated(@NotNull Integer articleId){
        return queryArticleImg(articleId);
    }
}
